//Copyright 2012 Trevin Liberty
//GNU GPL v3
//Author: Trevin Liberty

#include "camera.h"

Camera::Camera(int screenX, int screenY, int tileSize, int numTilesX, int numTilesY) {
	SCREEN_X = screenX;
	SCREEN_Y = screenY;
	this->tileSize = tileSize;
	this->numTilesX = numTilesX;
	this->numTilesY = numTilesY;
	pos.x = 1000;
	pos.y = 0;
}

void Camera::setXY(Point<float> pos) {
	if(pos.x < 0)
		this->pos.x = 0;
	else if(pos.x + SCREEN_X > numTilesX * tileSize)
		this->pos.x = numTilesX * tileSize - SCREEN_X;
	else
		this->pos.x = pos.x;

	if(pos.y < 0)
		this->pos.y = 0;
	else if(pos.y + SCREEN_Y > numTilesY * tileSize)
		this->pos.y = numTilesY * tileSize - SCREEN_Y;
	else
		this->pos.y = pos.y;
}

void Camera::addToX(int t) {
	if(pos.x + t < 0)
		this->pos.x = 0;
	else if(pos.x + t + SCREEN_X > numTilesX * tileSize)
		this->pos.x = numTilesX * tileSize - SCREEN_X;
	else
		this->pos.x += t;
}

void Camera::addToY(int t) {
	if(pos.y + t < 0)
		this->pos.y = 0;
	else if(pos.y + t + SCREEN_Y > numTilesY * tileSize)
		this->pos.y = numTilesY * tileSize - SCREEN_Y;
	else
		this->pos.y += t;
}

void Camera::setScreenMaxXY(int maxX, int maxY) {
	SCREEN_X = maxX; 
	SCREEN_Y = maxY;

	if(pos.x + maxX > numTilesX * tileSize)
		pos.x = numTilesX * tileSize - SCREEN_X;
	if(pos.y + + maxY > numTilesY * tileSize)
		pos.y = numTilesY * tileSize - SCREEN_Y;
}